import axios from "axios";
import Cookie from "js-cookie";

const instance = axios.create({
  baseURL: "https://mock.apifox.com/m1/3488924-0-default",
  timeout: 15000,
});

//拦截器
instance.interceptors.request.use(
  (config) => {
    let token = Cookie.get("token");
    let apifoxToken = "x7zvoM6wvrCbc1mpWeVSxlt5shtUlUpI";
    if (token) {
      config.headers = config.headers || {};
      config.headers.Authorization = token;
      config.headers.apifoxToken = apifoxToken;
    }
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);

instance.interceptors.response.use(
  (result) => {
    return result.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default instance;
